package com.jinmei.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.jinmei.dao.EmployeeDao;
import com.jinmei.dao.ToDoListDao;
import com.jinmei.model.ToDoList;
import com.jinmei.service.ToDoListService;
import com.jinmei.utils.JinmeiConsts;

public class ToDoListServiceImpl implements ToDoListService {

	private ToDoListDao toDoListDao;
	
	private EmployeeDao employeeDao;
	
	@Override
	public List<ToDoList> getTasksByEmployeeId(String employeeId) throws DataAccessException {
		if(employeeId == null || "".equals(employeeId)){
			return new ArrayList<ToDoList>();
		}
		List<ToDoList> tasks = employeeDao.findEmployeeTasksByFid(Integer.valueOf(employeeId));
		if(tasks.isEmpty()){
			return new ArrayList<ToDoList>();
		}else{
			return tasks;
		}
	}

	@Override
	public String saveOrUpdateTask(ToDoList task) throws DataAccessException {
		try{
			toDoListDao.saveOrUpdateToDoList(task);
			return JinmeiConsts.SUCCEED;
		}catch(Exception e){
			e.printStackTrace();
			return JinmeiConsts.FAILED;
		}
	}

	@Override
	public String deleteTask(Integer taskId) throws DataAccessException {
		try{
			toDoListDao.deleteToDoList(taskId);
			return JinmeiConsts.SUCCEED;
		}catch(Exception e){
			return JinmeiConsts.FAILED;
		}
	}
	
	public ToDoListDao getToDoListDao() {
		return toDoListDao;
	}

	public void setToDoListDao(ToDoListDao toDoListDao) {
		this.toDoListDao = toDoListDao;
	}

	public EmployeeDao getEmployeeDao() {
		return employeeDao;
	}

	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}

}
